package
{
import com.pblabs.engine.PBE;
import com.pblabs.engine.components.TickedComponent;
      import com.pblabs.engine.entity.PropertyReference;

      import flash.geom.Point;

      public class SimpleEnemyLogicComponent extends TickedComponent
      {
            // The property of the enemy Entity that
            // defines its position
            public var positionReference:PropertyReference;
            // The property of the enemy Entity that
            // defines its size
            public var sizeReference:PropertyReference;
            // The speed at which the enemy will move down the screen
            public var speed:Number = 50;

            public function SimpleEnemyLogicComponent()
            {
            }

            // The onTick() function is called once per frame
            public override function onTick(tickRate:Number):void
            {
                  // Get the current position of the Entity
                  var position:Point = this.owner.getProperty(positionReference) || new Point();
                  // Move the position down the screen
                  position.y += speed * tickRate;
                  // Set the new position of the Entity
                  this.owner.setProperty(positionReference, position);

                  // Get the size of the Entity
                  var size:Point = this.owner.getProperty(sizeReference) || new Point();
                  // If the Entity has moved off the bottom of the screen,
                  // remove the Entity from the game
                  if (position.y > PBE.mainStage.stageHeight + size.y / 2)
                        owner.destroy();
            }
      }
}
